package com.example.eos.mapper;

import com.example.eos.bean.UserLabel;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserLabelMapper {

    @Select("select userlabelid, labelid from user_label where userid = #{userid,jdbcType=VARCHAR} order by labelnum asc")
    List<UserLabel> findByUserid(String userid);

    @Select("select count(*) from user_label where userid = #{userid,jdbcType=VARCHAR}")
    int findCountByUserid(String userid);

    @Select("select userlabelid from user_label where userid = #{userid,jdbcType=VARCHAR} and labelid = #{labelid,jdbcType=VARCHAR}")
    UserLabel findByUseridAndLabelid(@Param("userid") String userid, @Param("labelid")String labelid);

    @Insert("insert into user_label (userlabelid, userid, labelid, labelname, labelnum) values (#{userlabelid,jdbcType=VARCHAR}, #{userid,jdbcType=VARCHAR}, #{labelid,jdbcType=VARCHAR}, #{labelname,jdbcType=VARCHAR}, #{labelnum,jdbcType=INTEGER})")
    void save(UserLabel userLabel);

    @Delete("delete from user_label where userlabelid = #{userlabelid,jdbcType=VARCHAR}")
    void deteleByUserlabelid(String userlabelid);

    @Delete("delete from user_label where userid = #{userid,jdbcType=VARCHAR}")
    void deteleByUserid(String userid);

    @Delete("delete from user_label where userid = #{userid,jdbcType=VARCHAR} and labelid = #{labelid,jdbcType=VARCHAR}")
    void deteleByUseridAndLabelid(@Param("userid") String userid,@Param("labelid") String labelid);

}
